import { BasicDelModel } from '../model/baseModel';
import { ConfigGroupSearchModel, ConfigGroupVOModel, ConfigSearchModel, ConfigVOModel } from './model/configModel';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  GroupBaseApi = '/sys/config-group',
  ConfigBaseApi = '/sys/config',
  GetAllConfigsApi = '/sys/config/all',
}

/**
 * @description: 获取所有的配置信息
 */
export const getAllConfigApi = () => {
  return defHttp.post({ url: Api.GetAllConfigsApi }, { encrypt: false });
};

/**
 * @description: 获取系统配置分组列表数据
 */
export const getConfigGroupPageApi = (data: ConfigGroupSearchModel) => {
  return defHttp.post({ url: Api.GroupBaseApi + '/page', data });
};

/**
 * @description: 新增系统配置分组
 */
export const saveConfigGroupApi = (data: ConfigGroupVOModel) => {
  return defHttp.post({ url: Api.GroupBaseApi + '/add', data });
};

/**
 * @description: 修改系统配置分组
 */
export const updateConfigGroupApi = (data: ConfigGroupVOModel) => {
  return defHttp.post({ url: Api.GroupBaseApi + '/edit', data });
};

/**
 * @description: 删除系统配置分组
 */
export const delConfigGroupApi = (ids: string) => {
  const data: BasicDelModel = {
    ids: Array.isArray(ids) ? ids : [ids]
  }
  return defHttp.post({ url: Api.GroupBaseApi + '/delete', data });
};

/**
 * @description: 获取系统配置列表数据
 */
export const getConfigPageApi = (data: ConfigSearchModel) => {
  return defHttp.post({ url: Api.ConfigBaseApi + '/page', data });
};

/**
 * @description: 新增系统配置
 */
export const saveConfigApi = (data: ConfigVOModel) => {
  return defHttp.post({ url: Api.ConfigBaseApi + '/add', data });
};

/**
 * @description: 修改系统配置
 */
export const updateConfigApi = (data: ConfigVOModel) => {
  return defHttp.post({ url: Api.ConfigBaseApi + '/edit', data });
};

/**
 * @description: 删除系统配置
 */
export const delConfigApi = (ids: string[]) => {
  const data: BasicDelModel = {
    ids: ids
  }
  return defHttp.post({ url: Api.ConfigBaseApi + '/delete', data });
};
